struct Solution {}

fn main() {}

impl Solution {
    pub fn summary_ranges(nums: Vec<i32>) -> Vec<String> {
        if nums.len() == 0 {
            return [].to_vec();
        }
        if nums.len() == 1 {
            return vec![Self::build_ret_string(nums[0], nums[0])]
        }
        let mut ret: Vec<String> = Vec::new();
        let mut start_idx: usize = 0;
        let mut end_idx: usize = 1;

        for end_idx in 1..nums.len() {
            if nums[end_idx] == nums[end_idx - 1] + 1 {
                continue;
            }
            ret.push(Self::build_ret_string(nums[start_idx], nums[end_idx - 1]));
            start_idx = end_idx;
        }
        // 最后一组需要手动处理
        ret.push(Self::build_ret_string(nums[start_idx], nums[nums.len() - 1]));
        ret
    }

    pub fn build_ret_string(start: i32, end: i32) -> String {
        if start == end {
            return start.to_string();
        }
        start.to_string() + "->" + &end.to_string()
    }
}